package com.mj.listen2._01_排序.cmp;

public class _02_SelectSort<T extends Comparable<T>> extends Sort<T> {
    @Override
    protected void sort() {
        for (int end = array.length - 1; end > 0; end--) {
            // 记录最大值索引
            int maxIndex = 0;
            for (int begin = 1; begin <= end; begin++) {
                if (cmp(maxIndex, begin) <= 0) {
                    // 记录最大索引
                    maxIndex = begin;
                }
            }
            // 与最后位置进行交换
            swap(maxIndex, end);
        }
    }
}
